package cx.ath.skyflyer.gpslog.nmea;


import j2meunit.framework.*;

/**
 * @author Ahti Legonkov
 */
public class GpsFixDataTest extends TestCase {
    
    public GpsFixDataTest() {
    }

    private GpsFixDataTest(String name, TestMethod method) {
        super(name, method);
    }

    private GpsFixData nmea = null;

    public void setUp() {
        try {
            nmea = new GpsFixData("$GPGGA,090409.000,5859.2173,N,02443.4195,E,1,8,1.23,52.6,M,20.1,M,,*6C");
        }
        catch (ChecksumMismatchException ex) {
            fail("Set up: Unexpected checksum mismatch");
        }
    }

    public void tearDown() {
        //super.tearDown();
    }

    private void testGetAltitude() {
        final double expected = 52.6;
        final double test = nmea.getAltitude();
        assertEquals(expected, test);
    }

    private void testGetAltitudeUnit() {
        final String expected = "M";
        final String test = nmea.getAltitudeUnit();
        assertEquals(expected, test);
    }

    private void testGetFixQuality() {
        final int expected = 1;
        final int test = nmea.getFixQuality();
        assertEquals(expected, test);
    }

    private void testGetLatitude() {
        final double expected = NmeaUtils.degreesToRadians("5859.2173"); // North
        final double test = nmea.getLatitude();
        assertEquals(expected, test);
    }

    private void testGetLatitude1() {

        GpsFixData fix = null;
        try {
            fix = new GpsFixData("$GPGGA,090409.000,5859.2173,S,02443.4195,E,1,8,1.23,52.6,M,20.1,M,,*71");
        }
        catch (Exception e)  {
            this.fail();
            return;
        }

        final double expected = -NmeaUtils.degreesToRadians("5859.2173"); // South
        final double test = fix.getLatitude();
        assertEquals(expected, test);
    }

    private void testGetLongitude() {
        final double expected = NmeaUtils.degreesToRadians("02443.4195"); // East
        final double test = nmea.getLongitude();
        assertEquals(expected, test);
    }

    private void testGetLongitude1() {

        GpsFixData fix = null;
        try {
            fix = new GpsFixData("$GPGGA,090409.000,5859.2173,S,02443.4195,W,1,8,1.23,52.6,M,20.1,M,,*63");
        }
        catch (Exception e)  {
            this.fail();
            return;
        }

        final double expected = -NmeaUtils.degreesToRadians("02443.4195"); // West
        final double test = fix.getLongitude();
        assertEquals(expected, test);
    }

    private void testGetNumberOfSatellites() {
        final int numberOfSatellites = nmea.getNumberOfSatellites();
        final int expected = 8;
        assertEquals(expected, numberOfSatellites);
    }

    private void testGetTime() {
        Time time = nmea.getTime();
        Time expected = new Time("090409.000");
        assertEquals(expected, time);
    }

    public Test suite() {
        TestSuite ts = new TestSuite();

		ts.addTest(new GpsFixDataTest("testGetLongitude", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetLongitude();
            }
        }));

		ts.addTest(new GpsFixDataTest("testGetLongitude1", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetLongitude1();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetLatitude", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetLatitude();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetLatitude1", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetLatitude1();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetAltitude", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetAltitude();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetAltitudeUnit", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetAltitudeUnit();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetFixQuality", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetFixQuality();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetNumberOfSatellites", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetNumberOfSatellites();
            }
        }));

        ts.addTest(new GpsFixDataTest("testGetTime", new TestMethod() {
            public void run(TestCase tc) {
                ((GpsFixDataTest)tc).testGetTime();
            }
        }));

        return ts;
    }
}
